<?
require_once($r."_config/db.php");
require_once($r."_config/site.php");
require_once($r."_engine/c_sql_table.php");

$g_st_plan = new CSqlTable("accounts", "id");

class CPlan
{
	var $id, $data;
	
	function CPlan($id)
	{
		$this->LoadById($id);
	}
	
	function CreateNew()
	{
		//TODO: take example from CAccount class
	}
	
	function InitNew()
	{
		//TODO: take example from CAccount class
	}
	
	function ReadRegInfoFromForm()
	{
		//TODO: take example from CAccount class
	}
	
	
	function LoadById($id)
	{
		return $this->LoadByQuery(
			"SELECT * FROM plans WHERE id='$id';"
		);
	}
	function LoadByQuery($query)
	{
		global $g_st_plan;
		$row = $g_st_plan->SelectRow($query);
		if (!$row) return false;
		$this->LoadFromArray($row);
		return true;
	}
	
	function LoadFromArray($row)
	{
		foreach($row as $f => $v)
		{
			if (is_int($f)) continue;
			
			if ($f == "id")
				$this->id = $v;
			else
				$this->data[$f] = $v;
		}
	}
	
	function Update($values)
	{
		global $g_st_plan;
		$this->LoadFromArray($values);
		return $g_st_plan->Update($values, $this->id);
	}
}
?>